import { uuid } from '../utils/uuid';
import { resumeRepository, ResumeEntity } from '../utils/repository';
import { Service } from 'typedi';

@Service()
export class ResumeService {
  async save(entity: ResumeEntity) {
    const resume = await resumeRepository.findOneBy({ name: entity.name, type: entity.type });
    if (resume) {
      const { affected } = await resumeRepository.update(resume.id, entity);
      return affected;
    }
    entity.rid = uuid.simpleUUID();
    const { raw } = await resumeRepository.insert(entity);
    return raw.affectedRows;
  }

  async select(uid: string) {
    return await resumeRepository.find({ where: { uid } });
  }
}
